//---------------开始表示-----------------------
//===============结束表示=====================




window.onload = function(){
	var color = ['#B4C843','#BBF1FE','#FAF9FE','#FFFFFF','#262729','#E9E9EB'];
	var show = document.getElementsByClassName('main_goods_show');
	var click = document.getElementsByClassName('clickList');
	var fuck = document.getElementById('f_home');
	var home = document.getElementById('home');	
	var left =document.getElementById('left_arrow');
	var right =document.getElementById('right_arrow');
	var run = document.getElementById('js_content');
	var small =document.getElementById('small');
	var big =document.getElementById('big');
	// var back = document.getElementsByClassName('f_home');
	var num = 0;
	var opac = null;
//----------------控制左右轮换-----------------------	
	right.onclick = function(){
		goods();
	}

	left.onclick = function(){			
		num = num-2;
		if (num == -2) {
		 	num = show.length-2;
		}else if(num == -1){
			num = show.length-1;			
		}
		goods();		
	}
//===============================================
//--------------------------轮换--------------------
	var goods = function (){		
		for (var i = 0; i < show.length; i++) {
			show[i].style.display="none";
			click[i].style.backgroundColor="";
			}
		show[num].style.display="block";
		click[num].style.backgroundColor="#00C3F5";
		fuck.style.backgroundColor = color[num];
		num++;
		if(num == show.length){
			num = 0;
			}	
		}


	var time = setInterval(goods, 2000);	

	
//-------------点击小点随意切换轮换图------------------
	for (var i = 0; i <click.length; i++) {

		do_click(i);
	}

	function do_click(i) {

		click[i].onclick = function() {
			num = i;
			goods();
		}
	}	

//======================================================

//--------------------移入停止轮播-----------------------//
	fuck.onmouseover = function  () {

		clearTimeout(time);
	}

	fuck.onmouseout = function () {		
		
		time = setInterval(goods, 2000);
	}
//==========================================================
//-----------------淡入淡出------------------------------//	
	var time2=function(){} ,time1=function(){};
	home.onmouseover =function(){			
		runtime_over();
	}
	home.onmouseout =function(){
		runtime_out();
	}
	function runtime_over(){
		time1 = setInterval(opacity_over, 20); 
	}
	function runtime_out(){
		time2 = setInterval(opacity_out, 20); 
	}		
	function opacity_out(){
		clearInterval(time1);
		if ( opac > 0){
			opac -=0.1;
		}else{
			opac = 0;
			clearInterval(time2);
		}
		home.children[2].style.opacity = opac;
		home.children[3].style.opacity = opac;
	}
	function opacity_over(){
		clearInterval(time2);
		if ( opac < 0.8){
			opac +=0.1;
		}else{	
			opac = 0.8;
			clearInterval(time1);			
		}
		home.children[2].style.opacity = opac;
		home.children[3].style.opacity = opac;
	}
	//var time3 = setInterval(home.onmouseover, 125);


//===================================================	
//------------------左右群轮换的图片----------------
	var x = 0;
	var speed = 0;
	var add = 0;
	var time3 = function(){};
	var time4 = function(){};
	big.onclick =function(){
		//alert(0000);	
		//if (run.style.left <= 2480&& )	
		var add =parseInt(run.style.left);
		speed = add;
		clearInterval(time4);
		runtime_right();
	}
	small.onclick =function(){
		clearInterval(time3);
		var add =parseInt(run.style.left);
		speed = add;
		runtime_left();

	}	
	function runtime_right(){
		
		time3 = setInterval(go_right,50);
	}
	function runtime_left(){
		time4 = setInterval(go_left,50);
	}


	function go_right(){
	
		var cont = parseInt(run.style.left);
		x += Math.PI/40;
		if(x >=0&&x < 0.5){
			speed -=1220/20*Math.pow(x,4);
		}else if ( x >= 0.5 && x <= (4/5)*Math.PI){	
			//alert(x);
			speed -=(1220/20)*Math.abs(Math.sin(x));
			//alert(speed);
		}else if( cont < -1220){
			speed +=15;
			if(-2420 >= cont&&cont >= -2440){
				speed = -2440;
				run.style.left = speed+'px';
				clearInterval(time3);
				x = 0;
			}

		}else if(-1200 >= cont&&cont >= -1220){	
			speed = -1220;
			run.style.left = speed+'px';
			clearInterval(time3);
			x = 0;
		} 		
	
		run.style.left = speed+'px';		
	}
	function go_left(){
		var cont = parseInt(run.style.left);
		x += Math.PI/40;
		if(x >=0&&x < 0.5){
			speed +=1240/20*Math.pow(x,4);
		}else if ( x >= 0.5 && x <= (4/5)*Math.PI){				
			speed +=(1240/20)*Math.abs(Math.sin(x));		
		}else if(cont > -1220 ){
			speed -= 15;			
			if(cont > 0&&cont < 20){	
			speed = 0;
			run.style.left = speed+'px';			
			clearInterval(time4);
			x = 0;
			if(cont >= -1260 && cont <= -1220 ){
				speed -= 0;
				speed = -1220;
				run.style.left = speed+'px';			
				clearInterval(time4);
				x = 0;
			}
			
		} 
		}		
		//alert(speed);
		run.style.left = speed+'px';	
	}

}

